package com.yiwei.hdb.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yiwei.hdb.R;
import com.yiwei.hdb.model.BankCardListModel;
import com.yiwei.hdb.model.BankListModel;
import com.yiwei.hdb.model.BankModel;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 18-9-18.
 */

public class BankListFragment extends BaseFragment {
    @BindView(R.id.img_icon)
    ImageView imgIcon;
    @BindView(R.id.txt_name)
    TextView txtName;
    @BindView(R.id.txt_type)
    TextView txtType;
    @BindView(R.id.txt_card_no)
    TextView txtCardNo;
    @BindView(R.id.layout_total)
    RelativeLayout layoutTotal;
    Unbinder unbinder;
    private BankCardListModel.DataBean data;
    private int poi;
    private int[] bg_res = new int[]{R.mipmap.img_bankcar_bg_one, R.mipmap.img_bankcar_bg_two, R.mipmap.img_bankcar_bg_three, R.mipmap.img_bankcar_bg_four};

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_bank_list;
    }

    public void setData(int poi, BankCardListModel.DataBean data) {
        this.poi = poi;
        this.data = data;
    }

    @Override
    protected void initView() {
        if (data != null && data.bank != null) {
            txtName.setText(data.bank.bank_card_type);
            txtType.setText(data.card_type);
            if (!TextUtils.isEmpty(data.bankcard) && data.bankcard.length() >= 5) {
                txtCardNo.setText("**** **** **** " + data.bankcard.substring(data.bankcard.length() - 4, data.bankcard.length()));
            }
            layoutTotal.setBackgroundResource(bg_res[poi % 4]);
        }

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
